package com.mavenTest.test;

import com.mavenTest.dao.ProductDao;
import com.mavenTest.entity.Product;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author XIAOLIANG
 * @ClassName test.java
 * @Description TODO
 * @createTime 2021年03月05日 16:09:00
 */

public class test {
	public static void main(String[] args) {

		InputStream stream = null;
		try {
			stream = Resources.getResourceAsStream("mybatis-config.xml");
		} catch (IOException e) {
			e.printStackTrace();
		}
		SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(stream);
		SqlSession sqlSession = sqlSessionFactory.openSession();
		ProductDao mapper = sqlSession.getMapper(ProductDao.class);
		Product product = mapper.selectOnrById(20);

		sqlSession.close();
		System.out.println(product);

	}
}
